package com.itgacl.magic4j.libcommon.component.delayQueue.service.impl;

import com.itgacl.magic4j.libcommon.component.delayQueue.bean.QueueData;
import com.itgacl.magic4j.libcommon.component.delayQueue.manager.DelayQueueManager;
import com.itgacl.magic4j.libcommon.component.delayQueue.service.DelayQueueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.List;

@Service
public class DelayQueueServiceImpl implements DelayQueueService {

    @Autowired
    private DelayQueueManager delayQueueManager;

    @Override
    public void commit(String message) {
        delayQueueManager.commit(message);
    }

    @Override
    public void commit(String msgId, String message) {
        delayQueueManager.commit(msgId, message);
    }

    @Override
    public void commit(String message, Long timestamp) {
        delayQueueManager.commit(message, timestamp);
    }

    @Override
    public void commit(String msgId, String message, Long timestamp) {
        delayQueueManager.commit(msgId, message, timestamp);
    }

    @Override
    public void commit(String message, Date delayTime) {
        commit(message, delayTime.getTime());
    }

    @Override
    public void commit(String message, LocalDateTime delayTime) {
        long timestamp = delayTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        commit(message, timestamp);
    }

    @Override
    public void commit(String msgId, String message, Date delayTime) {
        commit(msgId,message, delayTime.getTime());
    }

    @Override
    public void commit(String msgId, String message, LocalDateTime delayTime) {
        long timestamp = delayTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        commit(msgId,message, timestamp);
    }

    @Override
    public QueueData getByMsgId(String msgId) {
        return delayQueueManager.get(msgId);
    }

    @Override
    public void sendMessage(String msgId) {
        delayQueueManager.sendDelayMessage(msgId);
    }

    @Override
    public List<QueueData> getAll() {
        return delayQueueManager.getAll();
    }
}
